﻿
namespace ConsoleTest
{
    public static class TriangleChecker
    {
        public enum TriangleType
        {
            Scalene = 1,
            Isosceles,
            Equilateral,
            NotATriangle
        }

        /// <summary>
        /// Checks triangle's sides and returns the type of triangle.
        /// </summary>
        public static TriangleType CheckTriangle(int sideA, int sideB, int sideC)
        {
            // a point and a line are not a triangle, from our point of view :)
            if ((sideA <= 0) || (sideB) <= 0 || (sideC <= 0))
                return TriangleType.NotATriangle;

            // we could save one comparison, but let's leave this as it is for clarity
            var aEqualsB = sideA == sideB;
            var bEqualsC = sideB == sideC;
            var aEqualsC = sideA == sideC;

            if (aEqualsB)
            {
                if (bEqualsC)
                    return TriangleType.Equilateral; // nothing to check any more here

                // checking if it's a valid triangle
                return (sideA + sideB) < sideC ? 
                    TriangleType.NotATriangle : TriangleType.Isosceles;
            }

            if (bEqualsC)
            {
                // checking if it's a valid triangle
                return (sideB + sideC) < sideA ? 
                    TriangleType.NotATriangle : TriangleType.Isosceles;
            }

            if (aEqualsC)
            {
                // checking if it's a valid triangle
                return (sideA + sideC) < sideB ? 
                    TriangleType.NotATriangle : TriangleType.Isosceles;
            }

            // the worst case - need to check all three sides, 
            // to be sure, that it's a valid triangle
            if
            (
                ((sideA + sideB) < sideC)
                ||
                ((sideB + sideC) < sideA)
                ||
                ((sideA + sideC) < sideB)
            )
                return TriangleType.NotATriangle;

            // this is just a triangle
            return TriangleType.Scalene;
        }
    }
}
